package com.jwong.grpc.loadbalancer;

import io.grpc.NameResolver;
import io.grpc.NameResolverProvider;

import java.net.URI;

public class DirectMultiAddressNameResolverProvider extends NameResolverProvider {

    private static final String SCHEME = "direct";

    @Override
    protected boolean isAvailable() {
        return true;
    }

    @Override
    protected int priority() {
        return 5;
    }

    @Override
    public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
        String targetPath = targetUri.toString();
        targetPath = targetPath.replace("direct://", "");
        return new DirectMultiAddressNameResolver(targetPath);
    }

    @Override
    public String getDefaultScheme() {
        return SCHEME;
    }
}
